<template>
  <div>
    <div>
      <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="50%"
      :showClose="false"
      >
      <div>
        <template>
          <el-table
              :data="tableData"
              :cell-style="{'text-align':'center'}"
              :header-cell-style="{background:'#f5f5f5','text-align':'center'}"
              border
              style="width: 100%">
              <el-table-column
                      label="测点标识"
                      prop="itemTag"
                     >
                    </el-table-column>
                    <el-table-column
                      prop="itemName"
                      label="测点名称"
                      >
                      <template #default="{row}">
                        <el-input size="mini" v-model="row.itemName"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="测点地址"
                      prop="dataAddress"
                     >
                     <template #default="{row}">
                        <el-input size="mini" v-model="row.dataAddress"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="holdAlarm"
                      label="使能开关"
                     >
                     <template #default="{row}">
                        <el-select v-model="row.holdAlarm"   clearable  size="mini" style="margin-right: 10px;" >
                          <el-option class="select" label="是" :value="true"></el-option>
                          <el-option class="select" label="否" :value="false"></el-option>
                        </el-select>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="控制模式"
                      prop="controlMode"
                      width="150">
                      <template #default="{row}">
                        <el-select v-model="row.controlMode"   clearable    size="mini" style="margin-right: 10px;" >
                          <el-option class="select" v-for="(item,index) in xialalist" :key="index" :label="item.text" :value="item.value"></el-option>
                        </el-select>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="controlCode"
                      label="控制编号"
                      >
                      <template #default="{row}">
                        <el-input size="mini" v-model="row.controlCode"></el-input>
                      </template>
                    </el-table-column>
            </el-table>
        </template>
      </div>
      <span  class="dialog">
          <button class="button" type="primary" @click="submit" style=" cursor: pointer;">确 定</button>
          <button @click="dialogVisible = false" style=" cursor: pointer;">取 消</button>
        </span>
    </el-dialog>
    </div>
  </div>
</template>

<script>
import { getpicedianlistapi, getkongzhiapi, postpiliangputapi, postpixiucedianapi } from '@/api/measure'
import { putpiliangapi } from '@/api/device'
export default {
  name: 'MaintenanceYaokong',
  props: {
    changeselect: {
      type: Array
    },
    flag: {
      type: String
    }
  },
  data () {
    return {
      tableData: [],
      dialogVisible: false,
      xialalist: []
    }
  },

  async mounted () {
    const res = await getkongzhiapi()
    this.xialalist = res.data.list
  },

  methods: {
    async getgetpicedianlist () {
      const arr = this.changeselect.map(ele => ele.id)
      if (this.flag) {
        const res = await postpixiucedianapi(arr)
        this.tableData = res.data.list
      } else {
        const res = await getpicedianlistapi(arr)
        this.tableData = res.data.list
      }
    },
    async submit () {
      if (this.flag) {
        await putpiliangapi(this.tableData)
      } else {
        await postpiliangputapi(this.tableData)
      }

      this.dialogVisible = false
      this.$message.success('修改成功')
      this.$emit('shuxing')
    }
  },
  watch: {
    dialogVisible (val) {
      if (val) {
        this.getgetpicedianlist()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog{
  display: inline-block;
  margin: 0 auto;
  width: 100%;
  text-align: center;
  margin-top: 10px;
}
.dialog button{
  width:70px;
  height:30px;
  background-color:#fff;
  border-radius:5px;
  border:1px solid #ccc;
  margin-left:5px;
}
.button{
  background-color: #169bd5 !important;
  color: #fff;
}
.neww{
  margin: 0 90px 0 10px;
  background-color: #fff !important;
  color: black !important;
  border: 1px solid #ccc !important;
}
.button{
  width: 63px;
  height: 32px;
  border-radius: 3px;
  color: #fff;
  border: 1px solid #ccc;
  background-color: #1890ff;
}
</style>
